<?php
/**
 * Created by Pako
 * Date: 2019/2/8
 * Time: 17:07
 */

namespace App\Http\Controllers\Admin\Product;


use App\Http\Controllers\Controller;
use App\Http\Request\Product\TemplateStore;
use App\Repositories\Product\TemplateRepository;
use Illuminate\Http\Request;

class TemplateController extends Controller
{
    private $template ;

    public function __construct(TemplateRepository $template)
    {
        $this->template = $template;
    }

    public function index()
    {
        return $this->template->index();
    }

    public function show($template_id)
    {
        return $this->template->show($template_id);
    }

    /**
     * 描术
     *
     * @author Pako
     * @createTime 2019/2/8 17:47
     * @param TemplateStore $template
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \Illuminate\Validation\ValidationException
     */
    public function store(TemplateStore $template, Request $request)
    {
        $params = $template->validated($request);
        return $this->template->store($params);
    }

    /**
     * 描术
     *
     * @author Pako
     * @createTime 2019/2/8 17:47
     * @param TemplateStore $template
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \Illuminate\Validation\ValidationException
     */
    public function update(TemplateStore $template, Request $request)
    {
        $params = $template->validated($request);
        return $this->template->save($params);
    }

    public function delete(Request $request)
    {
        $template_ids = $request->input('template_ids',[]);
        return $this->template->del($template_ids);
    }
}